{include file="public/head"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">编辑字段</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段类型</label>
                            <div class="layui-input-inline">
                                <select id="type" disabled name="type" lay-filter="type" class="required" lay-verify="required">
                                    <option value='' >请选择字段类型</option>
                                    {volist name="type" id="vo"}
                                    <option {if($info.type eq $vo.name)} selected{/if} value="{$vo.name}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">字段名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="field" value="{$info.field}" lay-verify="required" placeholder="必填：字段名" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">别名|字段注释</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" value="{$info.name}" lay-verify="required" placeholder="必填：别名" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                       <div class="layui-col-lg12" id="field_setup">

                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">验证规则</label>
                            <div class="layui-input-inline">
                                <select name="pattern" lay-verify="required">
                                    {volist name="pattern" id="vo"}
                                    <option {if ($info.pattern eq $vo.name)}selected{/if} value="{$vo.name}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">class名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="class" value="{$info.class}" lay-verify="required" placeholder="请输入class名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">是否必填</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="required" {if($info.required eq 1)}checked{/if} value="1" title="是">
                                    <input type="radio" name="required" {if($info.required eq 0)}checked{/if} value="0" title="否">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">字符长度</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="minlength" value="{$info.minlength}" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="maxlength" value="{$info.maxlength}" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row layui-col-space10 layui-form-item">
                            <div class="layui-col-lg6">
                                <label class="layui-form-label">错误信息</label>
                                <div class="layui-input-block">
                                    <input type="text" name="errormsg" value="{$info.errormsg}" placeholder="验证失败错误信息" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="moduleid" value="{:input('mid')}">
                                <input type="hidden" name="id" value="{:input('id')}">
                                <input type="hidden" name="oldfield" value="{$info.field}">
                                <button class="layui-btn" lay-submit lay-filter="edit-but">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
    layui.config({
        base: '__LAYDMIN__/',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form'],function(){
				var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element,form = layui.form,mid = $('#mid').val();
				var info = {:json_encode($info,true)};
				field_setting(info);
				form.on('select(type)', function(type){
					field_setting(type);
				});
				
			//编辑提交
			form.on('submit(edit-but)', function(data){
				admin.req({
					url: '{:url(SYS_PATH."/field/edit")}' //实际使用请改成服务端真实接口
					, type: 'post'
					, data: data.field
					,success: function (res) {
						if(res.code==0){
										window.top.layer.msg(res.msg, {icon: 1, time: 1000,shade:[0.5,'#000000']}, function () {
											layer.closeAll("iframe");
											//刷新父页面
											parent.location.reload();
										});
						}else{
											window.top.layer.msg(res.msg, {icon: 2, time: 1000,shade:[0.5,'#000']});
											return;
						}
					}
				});
			});					
				
				//获取字段类型HTMl
				function field_setting(type) {
					var data = type.setup;
					var url =  "{:url('fieldType')}?mid={:input('mid')}&type="+type.type+"&name={$info.field}";
					$.ajax({
						type: "POST",
						url: url,
						data: data,
						beforeSend:function(){
							$('#field_setup').html('<i class="fa fa-spinner fa-spin fa-fw"></i>');
							form.render()
						},
						success: function(msg){
							$('#field_setup').html(msg);
							form.render()
						},
						complete:function(){
						},
						error:function(){
						}
					});
				}
    });
</script>
</body>
</html>